<?php
/**
 * Created by PhpStorm.
 * User: hotpot
 * Date: 2018/4/23
 * Time: 15:43
 */

namespace Home\Controller;

class TreeController {
    //定义一个空的数组
    static public $treeList = array();
    //接收$data二维数组,$pid默认为0，$level级别默认为1，id,pid,进行递归
    static public function tree($data,$pid=0,$level = 1){
        foreach($data as $v){
            if($v['about_pid']==$pid){
                $v['level']=$level;
                self::$treeList[]=$v;//将结果装到$treeList中
                self::tree($data,$v['about_id'],$level+1);
            }
        }
        return self::$treeList ;
    }
}